layui.use(['table','jquery','layer','form'],function () {
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;

    var orderTable = table.render({
        elem:"#root",
        url:'/course/getAllCourse',
        toolbar:'#toptool',
        defaultToolbar:['print','filter','exports'],
        page:true,
        limit:15,
        limits:[10,20,30],
        cols:[[
            {type:'checkbox',align:'center',width:60},
            {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                    return data.LAY_INDEX;
                }},
            {field:'nickname',title:'用户昵称',align:'center'},
            {field:'phone',title:'用户手机',align:'center'},
            {field:'orderSource',title:'订单来源',align:'center',templet:function (data) {
                    if (data.orderSource=="2"){
                        data.orderSource = "小程序";
                    }else if (data.orderSource=="3"){
                        data.orderSource = "app";
                    }
                    return "<p>"+data.orderSource+"</p>";
                }},
            {field:'orderStatus',title:'订单状态',align:'center',templet:function (data) {
                    if (data.orderStatus=="2"){
                        data.orderStatus = "未付款";
                    }else if (data.orderStatus=="3"){
                        data.orderStatus = "已付款";
                    }else if(data.orderStatus=="4"){
                        data.orderStatus = "待发货";
                    }else if(data.orderStatus=="5"){
                        data.orderStatus = "已发货";
                    }else if(data.orderStatus=="6"){
                        data.orderStatus = "已签收";
                    }else if(data.orderStatus=="7"){
                        data.orderStatus = "退货申请";
                    }else if(data.orderStatus=="8"){
                        data.orderStatus = "退货中";
                    }else if(data.orderStatus=="9"){
                        data.orderStatus = "已退货";
                    }else if(data.orderStatus=="10"){
                        data.orderStatus = "取消交易";
                    }else if(data.orderStatus=="11"){
                        data.orderStatus = "拒绝退货";
                    }
                    return "<p>"+data.orderStatus+"</p>";
                }},
            {field:'courseName',title:'课程名称',align:'center'},
            {field:'courseIntro',title:'课程描述',align:'center'},
            {field:'orderPaymentChannel',title:'支付渠道',align:'center',templet:function(data){
                    if (data.orderPaymentChannel == "2"){
                        data.orderPaymentChannel = "微信支付";
                    }else if (data.orderPaymentChannel =="3"){
                        data.orderPaymentChannel = "余额支付";
                    }
                    return "<p>"+data.orderPaymentChannel+"</p>";
                }},
            {field:'trueName',title:'主讲师',align:'center'},
            {title:'操作',align:'center',templet:function (data) {
                    var tem = '<a  href="javascript:getLogById('+data.orderId+');" style="color:rgb(13,171,158)">查看</a>' +
                        '<a  href="javascript:removeLogById('+data.orderId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                    return tem;
                }},
        ]]
    });

    /* 模糊查询 */
    form.on('submit(sub)',function (data) {
        orderTable.reload({
            url:'/course/getAllCourse?orderPaymentChannel='+data.field.orderPaymentChannel+'&orderSource='+data.field.orderSource+'&orderStatus='+data.field.orderStatus
        });
        return false;
    });
    /* 重置 */
    form.on('submit(subs)',function (data) {
        orderTable.reload({
            url:'/course/getAllCourse'
        });
    });
    /* 刷新 */
    form.on('submit(Refresh)',function (data) {
        orderTable.reload({
            url:'/course/getAllCourse'
        });
    });
    /* 详情开始 */
    getLogById = function getLogById(orderId) {
        $.ajax({
            url: "/course/getUser",
            type: "post",
            dataType: "json",
            data: {"orderId": orderId},
            success: function (data) {
                devicesMsg(data);
            },
        });
    }
    function devicesMsg(data) {
        layer.open({
            type: 2,
            title: "订单详情",
            area: ['800px', '590px'],
            shade: 0,
            maxmin:true,
            offset: 'auto',
            content: "/order/course-details.html",
            success: function (layero, index) {
                var obj = layero.find('iframe').contents();
                obj.find("#account").val(data.data.account);
                obj.find("#nickname").val(data.data.nickname);
                obj.find("#phone").val(data.data.phone);
                obj.find("#idCard").val(data.data.idCard);
                obj.find("#email").val(data.data.email);
                obj.find("#fullName").val(data.data.fullName);
                obj.find("#courseName").val(data.data.courseName);
                obj.find("#courseIntro").val(data.data.courseIntro);
            }
        });
    }
    /* 详情结束 */
    /* 删除 */
    removeLogById = function removeLogById(orderId){
        layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function(){
            $.ajax({
                url:"/course/delCourse",
                type:"post",
                dataType:"json",
                data:{"orderId":orderId},
                success:function(data){
                    layer.msg("删除成功");
                    orderTable.reload();
                }
            })
        });
    };
    Refresh = function Refresh() {
        location.reload();
    }

    //返回
    goBack = function goBack() {
        parent.$('#beforeHref').val($('.layui-elem-quote').children('span').eq(0).text());
        parent.before();
        return false;
    }


    //全部订单
    quanbu = function quanbu(){
        $("#quanbu").css('display','block');
        $("#pending").css('display','none');
        $("#tobecomm").css('display','none');
        $("#complete").css('display','none');
        orderTable.reload({
            url:'/course/getAllCourse'
        });
    }

    //代付款
    pending = function pending(){
        $("#quanbu").css('display','none');
        $("#pending").css('display','block');
        $("#tobecomm").css('display','none');
        $("#complete").css('display','none');
        var orderTable = table.render({
            elem:"#root",
            url:'/coursepend/getAllCourse',
            toolbar:'#toptool',
            defaultToolbar:['print','filter','exports'],
            page:true,
            limit:15,
            limits:[10,20,30],
            cols:[[
                {type:'checkbox',align:'center',width:60},
                {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:'nickname',title:'用户昵称',align:'center'},
                {field:'phone',title:'用户手机',align:'center'},
                {field:'orderSource',title:'订单来源',align:'center',templet:function (data) {
                        if (data.orderSource=="2"){
                            data.orderSource = "小程序";
                        }else if (data.orderSource=="3"){
                            data.orderSource = "app";
                        }
                        return "<p>"+data.orderSource+"</p>";
                    }},
                {field:'orderStatus',title:'订单状态',align:'center',templet:function (data) {
                        if (data.orderStatus=="2"){
                            data.orderStatus = "未付款";
                        }else if (data.orderStatus=="3"){
                            data.orderStatus = "已付款";
                        }else if(data.orderStatus=="4"){
                            data.orderStatus = "待发货";
                        }else if(data.orderStatus=="5"){
                            data.orderStatus = "已发货";
                        }else if(data.orderStatus=="6"){
                            data.orderStatus = "已签收";
                        }else if(data.orderStatus=="7"){
                            data.orderStatus = "退货申请";
                        }else if(data.orderStatus=="8"){
                            data.orderStatus = "退货中";
                        }else if(data.orderStatus=="9"){
                            data.orderStatus = "已退货";
                        }else if(data.orderStatus=="10"){
                            data.orderStatus = "取消交易";
                        }else if(data.orderStatus=="11"){
                            data.orderStatus = "拒绝退货";
                        }
                        return "<p>"+data.orderStatus+"</p>";
                    }},
                {field:'courseName',title:'课程名称',align:'center'},
                {field:'courseIntro',title:'课程描述',align:'center'},
                {field:'orderPaymentChannel',title:'支付渠道',align:'center',templet:function(data){
                        if (data.orderPaymentChannel == "2"){
                            data.orderPaymentChannel = "微信支付";
                        }else if (data.orderPaymentChannel =="3"){
                            data.orderPaymentChannel = "余额支付";
                        }
                        return "<p>"+data.orderPaymentChannel+"</p>";
                    }},
                {field:'trueName',title:'主讲师',align:'center'},
                {title:'操作',align:'center',templet:function (data) {
                        var tem = '<a  href="javascript:getLogById('+data.orderId+');" style="color:rgb(13,171,158)">查看</a>' +
                            '<a  href="javascript:removeLogById('+data.orderId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                        return tem;
                    }},
            ]]
        });
        /* 模糊查询 */
        form.on('submit(sub)',function (data) {
            orderTable.reload({
                url:'/coursepend/getAllCourse?orderPaymentChannel='+data.field.orderPaymentChannel+'&orderSource='+data.field.orderSource
            });
            return false;
        });
        /* 重置 */
        form.on('submit(subs)',function (data) {
            orderTable.reload({
                url:'/coursepend/getAllCourse'
            });
        });
        /* 刷新 */
        form.on('submit(Refresh)',function (data) {
            orderTable.reload({
                url:'/coursepend/getAllCourse'
            });
        });
        /* 查看 */
        getLogById = function getLogById(orderId) {
            $.ajax({
                url: "/course/getUser",
                type: "post",
                dataType: "json",
                data: {"orderId": orderId},
                success: function (data) {
                    devicesMsg(data);
                },
            });
        }
        function devicesMsg(data) {
            layer.open({
                type: 2,
                title: "订单详情",
                area: ['800px', '590px'],
                shade: 0,
                maxmin:true,
                offset: 'auto',
                content: "/order/course-details.html",
                success: function (layero, index) {
                    var obj = layero.find('iframe').contents();
                    obj.find("#account").val(data.data.account);
                    obj.find("#nickname").val(data.data.nickname);
                    obj.find("#phone").val(data.data.phone);
                    obj.find("#idCard").val(data.data.idCard);
                    obj.find("#email").val(data.data.email);
                    obj.find("#fullName").val(data.data.fullName);
                    obj.find("#courseName").val(data.data.courseName);
                    obj.find("#courseIntro").val(data.data.courseIntro);
                }
            });
        }
        /*表格详情结束*/

        /* 删除 */
        removeLogById = function removeLogById(orderId){
            layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function(){
                $.ajax({
                    url:"/coursepend/delOrder",
                    type:"post",
                    dataType:"json",
                    data:{"orderId":orderId},
                    success:function(data){
                        layer.msg("删除成功");
                        orderTable.reload();
                    }
                })
            });
        };
    };
    //代付款结束

    //未评论
    tobecomm = function tobecomm() {
        $("#quanbu").css('display', 'none');
        $("#pending").css('display', 'none');
        $("#tobecomm").css('display', 'block');
        $("#complete").css('display', 'none');
        var orderTable = table.render({
            elem:"#root",
            url:'/courseToBe/getAllCourse',
            toolbar:'#toptool',
            defaultToolbar:['print','filter','exports'],
            page:true,
            limit:15,
            limits:[10,20,30],
            cols:[[
                {type:'checkbox',align:'center',width:60},
                {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:'nickname',title:'用户昵称',align:'center'},
                {field:'phone',title:'用户手机',align:'center'},
                {field:'orderSource',title:'订单来源',align:'center',templet:function (data) {
                        if (data.orderSource=="2"){
                            data.orderSource = "小程序";
                        }else if (data.orderSource=="3"){
                            data.orderSource = "app";
                        }
                        return "<p>"+data.orderSource+"</p>";
                    }},
                {field:'orderStatus',title:'订单状态',align:'center',templet:function (data) {
                        if (data.orderStatus=="2"){
                            data.orderStatus = "未付款";
                        }else if (data.orderStatus=="3"){
                            data.orderStatus = "已付款";
                        }else if(data.orderStatus=="4"){
                            data.orderStatus = "待发货";
                        }else if(data.orderStatus=="5"){
                            data.orderStatus = "已发货";
                        }else if(data.orderStatus=="6"){
                            data.orderStatus = "已签收";
                        }else if(data.orderStatus=="7"){
                            data.orderStatus = "退货申请";
                        }else if(data.orderStatus=="8"){
                            data.orderStatus = "退货中";
                        }else if(data.orderStatus=="9"){
                            data.orderStatus = "已退货";
                        }else if(data.orderStatus=="10"){
                            data.orderStatus = "取消交易";
                        }else if(data.orderStatus=="11"){
                            data.orderStatus = "拒绝退货";
                        }
                        return "<p>"+data.orderStatus+"</p>";
                    }},
                {field:'courseName',title:'课程名称',align:'center'},
                {field:'courseIntro',title:'课程描述',align:'center'},
                {field:'orderPaymentChannel',title:'支付渠道',align:'center',templet:function(data){
                        if (data.orderPaymentChannel == "2"){
                            data.orderPaymentChannel = "微信支付";
                        }else if (data.orderPaymentChannel =="3"){
                            data.orderPaymentChannel = "余额支付";
                        }
                        return "<p>"+data.orderPaymentChannel+"</p>";
                    }},
                {field:'trueName',title:'主讲师',align:'center'},
                {field:'comment',title:'是否评论',align:'center',templet:function (data) {
                        if (data.comment==2){
                            data.comment = "待评论";
                        }else if (data.comment==3){
                            data.comment = "已评论";
                        }
                        return "<p>"+data.comment+"</p>";
                    }},
                {title:'操作',align:'center',templet:function (data) {
                        var tem = '<a  href="javascript:getLogById('+data.orderId+');" style="color:rgb(13,171,158)">查看</a>' +
                            '<a  href="javascript:removeLogById('+data.orderId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                        return tem;
                    }},
            ]]
        });

        /* 模糊查询 */
        form.on('submit(sub)',function (data) {
            orderTable.reload({
                url:'/courseToBe/getAllCourse?orderPaymentChannel='+data.field.orderPaymentChannel+'&orderSource='+data.field.orderSource
            });
            return false;
        });
        /* 重置 */
        form.on('submit(subs)',function (data) {
            orderTable.reload({
                url:'/courseToBe/getAllCourse'
            });
        });
        /* 刷新 */
        form.on('submit(Refresh)',function (data) {
            orderTable.reload({
                url:'/courseToBe/getAllCourse'
            });
        });
        /* 查看 */
        getLogById = function getLogById(orderId) {
            $.ajax({
                url: "/course/getUser",
                type: "post",
                dataType: "json",
                data: {"orderId": orderId},
                success: function (data) {
                    devicesMsg(data);
                },
            });
        }
        function devicesMsg(data) {
            layer.open({
                type: 2,
                title: "订单详情",
                area: ['800px', '590px'],
                shade: 0,
                maxmin:true,
                offset: 'auto',
                content: "/order/course-details.html",
                success: function (layero, index) {
                    var obj = layero.find('iframe').contents();
                    obj.find("#account").val(data.data.account);
                    obj.find("#nickname").val(data.data.nickname);
                    obj.find("#phone").val(data.data.phone);
                    obj.find("#idCard").val(data.data.idCard);
                    obj.find("#email").val(data.data.email);
                    obj.find("#fullName").val(data.data.fullName);
                    obj.find("#courseName").val(data.data.courseName);
                    obj.find("#courseIntro").val(data.data.courseIntro);
                }
            });
        }
        /*表格详情结束*/

        /* 删除 */
        removeLogById = function removeLogById(orderId){
            layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function(){
                $.ajax({
                    url:"/courseToBe/delOrder",
                    type:"post",
                    dataType:"json",
                    data:{"orderId":orderId},
                    success:function(data){
                        layer.msg("删除成功");
                        orderTable.reload();
                    }
                })
            });
        };
    }
    //未评论结束

    //已完成
    complete = function complete(){
        $("#quanbu").css('display','none');
        $("#pending").css('display','none');
        $("#tobecomm").css('display','none');
        $("#complete").css('display','block');
        var orderTable = table.render({
            elem:"#root",
            url:'/courseComp/getAllCourse',
            toolbar:'#toptool',
            defaultToolbar:['print','filter','exports'],
            page:true,
            limit:15,
            limits:[10,20,30],
            cols:[[
                {type:'checkbox',align:'center',width:60},
                {type:'orderId',title:'序号',align:'center',width:60,templet:function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:'nickname',title:'用户昵称',align:'center'},
                {field:'phone',title:'用户手机',align:'center'},
                {field:'orderSource',title:'订单来源',align:'center',templet:function (data) {
                        if (data.orderSource=="2"){
                            data.orderSource = "小程序";
                        }else if (data.orderSource=="3"){
                            data.orderSource = "app";
                        }
                        return "<p>"+data.orderSource+"</p>";
                    }},
                {field:'orderStatus',title:'订单状态',align:'center',templet:function (data) {
                        if (data.orderStatus=="2"){
                            data.orderStatus = "未付款";
                        }else if (data.orderStatus=="3"){
                            data.orderStatus = "已付款";
                        }else if(data.orderStatus=="4"){
                            data.orderStatus = "待发货";
                        }else if(data.orderStatus=="5"){
                            data.orderStatus = "已发货";
                        }else if(data.orderStatus=="6"){
                            data.orderStatus = "已签收";
                        }else if(data.orderStatus=="7"){
                            data.orderStatus = "退货申请";
                        }else if(data.orderStatus=="8"){
                            data.orderStatus = "退货中";
                        }else if(data.orderStatus=="9"){
                            data.orderStatus = "已退货";
                        }else if(data.orderStatus=="10"){
                            data.orderStatus = "取消交易";
                        }
                        return "<p>"+data.orderStatus+"</p>";
                    }},
                {field:'courseName',title:'课程名称',align:'center'},
                {field:'courseIntro',title:'课程描述',align:'center'},
                {field:'orderPaymentChannel',title:'支付渠道',align:'center',templet:function(data){
                        if (data.orderPaymentChannel == "2"){
                            data.orderPaymentChannel = "微信支付";
                        }else if (data.orderPaymentChannel =="3"){
                            data.orderPaymentChannel = "余额支付";
                        }
                        return "<p>"+data.orderPaymentChannel+"</p>";
                    }},
                {field:'trueName',title:'主讲师',align:'center'},
                {title:'操作',align:'center',templet:function (data) {
                        var tem = '<a  href="javascript:getLogById('+data.orderId+');" style="color:rgb(13,171,158)">查看</a>' +
                            '<a  href="javascript:removeLogById('+data.orderId+');" style="margin-left: 20px;color:rgb(13,171,158)">删除</a>';
                        return tem;
                    }},
            ]]
        });
        /* 模糊查询 */
        form.on('submit(sub)',function (data) {
            orderTable.reload({
                url:'/courseComp/getAllCourse?orderPaymentChannel='+data.field.orderPaymentChannel+'&orderSource='+data.field.orderSource
            });
            return false;
        });
        /* 重置 */
        form.on('submit(subs)',function (data) {
            orderTable.reload({
                url:'/courseComp/getAllCourse'
            });
        });
        /* 刷新 */
        form.on('submit(Refresh)',function (data) {
            orderTable.reload({
                url:'/courseComp/getAllCourse'
            });
        });
        /* 查看 */
        getLogById = function getLogById(orderId) {
            $.ajax({
                url: "/course/getUser",
                type: "post",
                dataType: "json",
                data: {"orderId": orderId},
                success: function (data) {
                    devicesMsg(data);
                },
            });
        }
        function devicesMsg(data) {
            layer.open({
                type: 2,
                title: "订单详情",
                area: ['800px', '590px'],
                shade: 0,
                maxmin:true,
                offset: 'auto',
                content: "/order/course-details.html",
                success: function (layero, index) {
                    var obj = layero.find('iframe').contents();
                    obj.find("#account").val(data.data.account);
                    obj.find("#nickname").val(data.data.nickname);
                    obj.find("#phone").val(data.data.phone);
                    obj.find("#idCard").val(data.data.idCard);
                    obj.find("#email").val(data.data.email);
                    obj.find("#fullName").val(data.data.fullName);
                    obj.find("#courseName").val(data.data.courseName);
                    obj.find("#courseIntro").val(data.data.courseIntro);
                }
            });
        }
        /*表格详情结束*/

        /* 删除 */
        removeLogById = function removeLogById(orderId){
            layer.confirm("确定删除？",{btn: ['确定', '取消'],title:"提示"}, function(){
                $.ajax({
                    url:"/courseComp/delOrder",
                    type:"post",
                    dataType:"json",
                    data:{"orderId":orderId},
                    success:function(data){
                        layer.msg("删除成功");
                        orderTable.reload();
                    }
                })
            });
        };
        //已完成结束
    };

    $("#b1").click(function () {
        yes('b1');
        no('b2');
        no('b3');
        no('b4');

    });
    $("#b2").click(function () {
        no('b1');
        yes('b2');
        no('b3');
        no('b4');

    });
    $("#b3").click(function () {
        no('b1');
        no('b2');
        yes('b3');
        no('b4');

    });
    $("#b4").click(function () {
        no('b1');
        no('b2');
        no('b3');
        yes('b4');

    });

    function no(id) {
        var box = document.getElementById(id);
        box.style.backgroundColor='#F5F7F9';
        box.style.color='#666666';
        box.style.border="1px solid #D2D2D2";
    }
    function yes(id) {
        var box = document.getElementById(id);
        box.style.backgroundColor='#009688';
        box.style.color='white';
        box.style.border="1px solid #D2D2D2";
    }


    Refresh = function Refresh() {
        location.reload();
    }

    //返回
    goBack = function goBack() {
        parent.$('#beforeHref').val($('.layui-elem-quote').children('span').eq(0).text());
        parent.before();
        return false;
    }

});
